﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using Petra.Gis.Geometry;
using Petra.Gis.Geometry.Support;
using Petra.Gis.Drawing;
using Petra.Gis.RenderingServices.PlanarBase ;

namespace Petra.Gis.Drawing.GDIPlus
{
  /// <summary>
  /// renders point as 'dot' in map of defined size and color
  /// </summary>
  public partial class SimplePointGridRenderer : GridRenderer
  {

    protected Pen _outpen;


    public SimplePointGridRenderer(MemGridMap map, Graphics g, DisplayTransformMatrix m, RenderStyle s)
      :base(map, g, m, s)
    {

      //parse style
      Pen _outpen = new Pen(Color.FromArgb((int)_style["Color"]), (int)_style["PointSize"]);

    }




    /// <summary>
    /// method that implements drawing (conversion) of gis geometry into output format geometry
    /// </summary>
    /// <param name="geometry">any system type currently</param>
    public override void RenderGeometry(GeometryBase geometry)
    {
      //validate type against supported types
      if (geometry is Petra.Gis.Geometry.Point)
        renderPoint((Petra.Gis.Geometry.Point)geometry);

      else if (geometry is MultiPoint)
        foreach (Petra.Gis.Geometry.Point p in (MultiPoint)geometry)
          renderPoint(p);

      else if (geometry is GeometryCollection)
        foreach (GeometryBase g in (GeometryCollection)geometry)
          RenderGeometry(g);

    }



    protected virtual void renderPoint(Petra.Gis.Geometry.Point pg)
    {

      System.Drawing.Point p = _transform.TransformPoint((Coordinate)pg.Origin[0]);
      _outGraphic.DrawEllipse(_outpen, p.X, p.Y, 0, 0);
    }




    public override DomainGeometryType RendererGeometryDomain
    {
      get { return DomainGeometryType.Point; }
    }



    public override bool IsRenderable(GeometryBase geometry)
    {
      //todo: update to linear only !!
      return true;
    }




    protected override RenderStyle renderStyle
    {
      get
      {
        return this.Style;
      }
      set
      {
        this.Style = value;
      }
    }



    public RenderStyle Style
    {
      get { return _style; }
      set
      {
        //todo: style must contain at least few items
        if (value == null)
          throw new ArgumentException("invalid null style", "style");

        _style = value;
      }
    }



  }
}
